﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using YYTea.MOdel.Model;
using YYTea.Services.IServices;
using YYTea.Services.VModel;

namespace youyouMiljyTea.Controllers
{

    [Route("api/[controller]")]
    [ApiController]
    public class ProductController : ControllerBase
    {
        protected readonly IProduct _product;
        public ProductController(IProduct product)
        {
            _product = product;
        }

        [HttpGet("GetAllProduct")]
        public async Task<List<Product>> GetAllProduct()
            => await _product.GetAllProduct();


        [HttpGet("GetProductById/Id")]
        public async Task<Product> GetProductById(Guid Id)
        {
            var proById = await _product.GetProductByID(Id);
            return proById;
        }
        [HttpPost("GetProductByName")]
        public async Task<List<Product>> GetProductByName(string Name)
        {
            var proByName = await _product.GetProductByName(Name);
            return proByName;
        }

        [HttpPost("AddProduct")]
        public async Task<Product> AddProduct(ProductVModel ProVM)
        {
            var proAdd = await _product.AddProduct(ProVM);
            return proAdd;
        }
        [HttpPut("UpdateProduct")]
        public async Task<ActionResult<Product>> UpdateProduct(ProductVModel ProVM)
        {
            var proUp = await _product.UpdateProduct(ProVM);
            if (proUp == null)
            {
                return NotFound();
            }
            return proUp;
        }
        [HttpDelete("DeleteProuct/Id")]
        public async Task<Product> DeleteProduct(Guid Id)
        {
            var depro = await _product.DeleteProduct(Id);
            return depro;
        }

    }
}
